package com.shop.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.domain.Spec;
import com.shop.goods.mapper.SpecMapper;
import com.shop.goods.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 靳润波
* @description 针对表【goods_spec】的数据库操作Service实现
* @createDate 2024-07-30 10:15:56
*/
@Service
public class SpecServiceImpl extends ServiceImpl<SpecMapper, Spec>
    implements SpecService{
    @Autowired
    private SpecMapper specMapper;
    @Override
    public List<Spec> selectAll() {
        LambdaQueryWrapper<Spec> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Spec::getIsDelete,0);
        return specMapper.selectList(queryWrapper);
    }

    @Override
    public Integer insert(Spec spec) {
        return specMapper.insert(spec);
    }

    @Override
    public Integer update(Spec spec) {
        return specMapper.updateById(spec);
    }

    @Override
    public Integer delete(Long id) {
        Spec spec = new Spec();
        spec.setId(id);
        spec.setIsDelete(1);
        return specMapper.updateById(spec);
    }

    @Override
    public List<Spec> selectList(Spec spec) {
        LambdaQueryWrapper<Spec> queryWrapper = this.lqw(spec);
        return specMapper.selectList(queryWrapper);
    }
    public LambdaQueryWrapper lqw(Spec spec){
        LambdaQueryWrapper <Spec> lqw = new LambdaQueryWrapper<>();
        if (spec.getId() != null){
            lqw.eq(Spec::getId,spec.getId());
        }
        if (spec.getSpecName() != null){
            lqw.eq(Spec::getSpecName,spec.getSpecName());
        }
        if (spec.getSpecValue() != null){
            lqw.eq(Spec::getSpecValue,spec.getSpecValue());
        }
        if (spec.getIsDelete() != null){
            lqw.eq(Spec::getIsDelete,spec.getIsDelete());
        }
        if (spec.getCreateTime() != null){
            lqw.eq(Spec::getCreateTime,spec.getCreateTime());
        }
        if (spec.getUpdateTime() != null){
            lqw.eq(Spec::getUpdateTime,spec.getUpdateTime());
        }
        return lqw;
    }

}




